package com.frxuexi.lib_base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitUtil {
    //获取OkHttpClient
    val parkClient by lazy {
        OkHttpClient.Builder()
            .readTimeout(30,TimeUnit.SECONDS)
            .writeTimeout(30,TimeUnit.SECONDS)
            .connectTimeout(30,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {chain->
                val request = chain.request().newBuilder()
                    .addHeader("token", SPUtils.getInstance().getString(Const.TOKEN,""))
//                    .addHeader("token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsImV4cCI6MTc0MjM2MzY5NiwidXNlcm5hbWUiOiJsciJ9.rH3oV2BvvUtWT9mqrX5VN_GrZsI9Q6G80CxGziLCxvQ")
                    .build()
                return@addInterceptor chain.proceed(request)
            }.build()
    }

    val parkRetrofit by lazy {
        Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(parkClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    val shopRetrofit by lazy {
        Retrofit.Builder()
            .baseUrl(Const.BASE_URL_SHOP)
            .client(parkClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    val hourseRetrofit by lazy {
        Retrofit.Builder()
            .baseUrl(Const.BASE_URL_HOURSE)
            .client(parkClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    val videoRetrofit by lazy {
        Retrofit.Builder()
            .baseUrl(Const.BASE_URL_VIDEO)
            .client(parkClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }


}